﻿Public Class MainPage
    Inherits System.Web.UI.MasterPage

	Public Sub Alert(ByVal msg As String)
		Me.MessageBox1.Alert(msg.Trim)
	End Sub

	Public Sub InjectJS(ByVal js As String)

		Me.ltrInjJS.Text = "<script language=""JavaScript"">" & js.ToString & "</script>"

	End Sub

	Public Sub ShowDepositMessage()
		If Not String.IsNullOrEmpty(GlobalApp.DepositMessage) Then
			Me.Alert(GlobalApp.DepositMessage)
			Me.Session.Remove(GlobalApp.sessionNameMessage)
		End If
	End Sub

	Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
		If GlobalApp.Authen Is Nothing Then
			Response.Redirect("login.aspx", False)
		End If
	End Sub

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		If HttpContext.Current.User.Identity.IsAuthenticated Then
			If GlobalApp.Authen Is Nothing Then
				Response.Redirect("login.aspx", False)
			Else

				'ซ่อน link
				Dim userinfo As Entity.UserInfoItem = GlobalApp.Authen
				Me.ltrCurrentAppId.Text = Common.Utility.FormatAppId(userinfo.user_id) '& " " & userinfo.fullname

				If HttpContext.Current.User.IsInRole("member") Then	'1=officer
					Me.hplViewProfile.NavigateUrl = "Profile.aspx"
				Else
					Me.hplViewProfile.NavigateUrl = "ViewStaffProfile.aspx"
				End If

				If HttpContext.Current.User.IsInRole("admin") Then
					ltrLinkAdmin.Visible = True
				Else
					ltrLinkAdmin.Visible = False
				End If

			End If
			ShowDepositMessage()
		Else
			Response.Redirect("login.aspx", False)
		End If
	End Sub

	Protected Sub lbtnLogOff_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lbtnLogOff.Click
		FormsAuthentication.SignOut()
		Session.RemoveAll()
		Response.Redirect("login.aspx", False)
	End Sub
End Class